<?php

require_once 'Zend/View/Helper/Abstract.php';

class Core_View_Helper_LoadModule extends Zend_View_Helper_Abstract
{
    /**
     * render a module page like news_showNewPosts
     */
    public function loadModule($module, $action, $params = array())
    {
        //validate the module
        $modules = Core_Filesystem_Dir::getDirectories(APPLICATION_PATH . '/modules');

        // @todo: validate the action as well
        if (in_array($module, $modules)) {
            if (is_array($params)) {
                foreach ($params as $k => $v) {
                    $paramsArray[(string)$k] = (string)$v;
                }
            }
            return $this->view->action($action, 'public', 'mod_' . $module, $paramsArray);
        }
    }
}